<template>
  <ol>
    <li @click="add">闭包</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
    <li>5</li>
  </ol>
</template>
<script lang="ts" setup>
function closeBag() {
  let count = 0;
  return function add() {
  count++;
  console.log(count);
};
}
const add = closeBag()

let dividedBy = (y:number) => {
    return function forX(x:number) {
        return x % y;
    }
}
let equalsTo = (y:number) => {
    return function forX(x:number) {
        return x === y;
    }
}

var remainderOfTwo = dividedBy(2);
var equalsToOne = equalsTo(1);

var isOdd = (x:number) => equalsToOne(remainderOfTwo(x));

console.log('5->',isOdd(5))
console.log('8->', isOdd(8))

function compose(...fns:any[]) {
    return fns.reverse().reduce( function reducer(fn1,fn2){
        return function composed(...args:any[]){
            return fn2( fn1( ...args ) );
        };
    } );
}
let isOdd1=compose(equalsToOne,remainderOfTwo)
console.log('compose->', isOdd1(21))

function reverseArgs(fn:any) {
    return function argsReversed(...args: any[]){
        return fn( ...args.reverse() );
    };
}

var pipe = reverseArgs(compose);
let isOdd2 = pipe(remainderOfTwo,equalsToOne)
console.log('pipe->', isOdd2(21))




</script>
<style></style>
  
